package com.mine.frame.mylandemo.mvp.presenter

import com.mine.frame.common.base.BasePresenter
import com.mine.frame.mylandemo.entity.forick.ControlBean
import com.mine.frame.mylandemo.mvp.iview.ICurtainHoneycomb
import com.third.device.mg.serialport.MGSerialPort

/**
 * @Date 2022/1/20
 * Description:
 */
class CurtainHoneycombPresenter(mIView: ICurtainHoneycomb) : BasePresenter<ICurtainHoneycomb>(mIView) {


    /**
     * 创建控制数据
     */
    fun createControlData(){
//*****************风琴帘设备*************************************************************************************
        val list = mutableListOf<ControlBean>()
        list.add(ControlBean(true ,"风琴帘指令" ))

        val onCurtain = ControlBean(false ,"风琴帘-群控-到达上限位")
        val comment = MGSerialPort.instance.getLeManLi().curtainAccordion().groupToUP(0)
        onCurtain.command = comment
        list.add(onCurtain)

        val stopCurtain = ControlBean(false ,"风琴帘-群控-停止")
        val stopComment = MGSerialPort.instance.getLeManLi().curtainAccordion().groupToStop(0)
        stopCurtain.command = stopComment
        list.add(stopCurtain)

        val downCurtain = ControlBean(false ,"风琴帘-群控-到达下限位")
        val downComment = MGSerialPort.instance.getLeManLi().curtainAccordion().groupToDown(0)
        downCurtain.command = downComment
        list.add(downCurtain)

        val query = ControlBean(false ,"风琴帘-状态查询-(不管ID，直接返回数据)")
        val queryComment = MGSerialPort.instance.getLeManLi().curtainAccordion().queryState()
        query.command = queryComment
        list.add(query)


        val queryID = ControlBean(false ,"风琴帘-状态查询ID=9-(ID对应才返回数据)")
        queryID.command = MGSerialPort.instance.getLeManLi().curtainAccordion().queryStateFromId(9)
        list.add(queryID)

        //根据id查询状态
        /*for (index in 0 until 100){
            val queryID = ControlBean(false ,"风琴帘-状态查询ID:$index-(ID对应才返回数据)")
            queryID.command = MGSerialPort.instance.getLeManLi().curtainAccordion().queryStateFromId(index.toByte())
            list.add(queryID)
        }*/

        //根据id控制下行
        /*for (index in 0 until 100){
            val down = ControlBean(false ,"风琴帘-下行 ID:$index")
            down.command = MGSerialPort.instance.getLeManLi().curtainAccordion().toDown(index.toByte())
            list.add(down)
        }*/


        /*id为0群控的上行*/
        val up0 = ControlBean(false ,"风琴帘-上行 ID:0群控")
        up0.command = MGSerialPort.instance.getLeManLi().curtainAccordion().toUp(0)
        list.add(up0)

        /*id为0群控的停止*/
        val stop0 = ControlBean(false ,"风琴帘-停止 ID:0群控")
        stop0.command = MGSerialPort.instance.getLeManLi().curtainAccordion().toStop(0)
        list.add(stop0)

        /*id为0群控的下行*/
        val down0 = ControlBean(false ,"风琴帘-下行 ID:0群控")
        down0.command = MGSerialPort.instance.getLeManLi().curtainAccordion().toDown(0)
        list.add(down0)

        //设置设备的ID为9
        val setId = ControlBean(false ,"风琴帘-设置ID=9 设置成功电机会正反转一次")
        setId.command = MGSerialPort.instance.getLeManLi().curtainAccordion().setDeviceID(9)
        list.add(setId)

        /*id为9的上行*/
        val up = ControlBean(false ,"风琴帘-上行 ID:9")
        up.command = MGSerialPort.instance.getLeManLi().curtainAccordion().toUp(9)
        list.add(up)

        /*id为9的停止*/
        val stop = ControlBean(false ,"风琴帘-停止 ID:9")
        stop.command = MGSerialPort.instance.getLeManLi().curtainAccordion().toStop(9)
        list.add(stop)

        /*id为9的下行*/
        val down = ControlBean(false ,"风琴帘-下行 ID:9")
        down.command = MGSerialPort.instance.getLeManLi().curtainAccordion().toDown(9)
        list.add(down)



        /*运行到指定位置*/
        val percentList = arrayListOf(0 ,20 , 30 ,50 ,80 , 100)
        percentList.forEach {
            val run = ControlBean(false ,"风琴帘-运行指定位置 run:$it%")
            run.command = MGSerialPort.instance.getLeManLi().curtainAccordion().runToValue(9 ,it)
            list.add(run)
        }


        /*id为9的设置上限位*//*
        val upLimit = ControlBean(false ,"风琴帘-设置上限位 ID:9")
        upLimit.command = MGSerialPort.instance.getLeManLi().curtainAccordion().setUpLimit(0)
        list.add(upLimit)

        *//*id为9的设置中间限位*//*
        val centerLimit = ControlBean(false ,"风琴帘-设置中间限位 ID:9")
        centerLimit.command = MGSerialPort.instance.getLeManLi().curtainAccordion().setCenterLimit(0)
        list.add(centerLimit)

        *//*id为9的设置下限位*//*
        val downLimit = ControlBean(false ,"风琴帘-设置下限位 ID:9")
        downLimit.command = MGSerialPort.instance.getLeManLi().curtainAccordion().setDownLimit(0)
        list.add(downLimit)

        *//*id为9的保存限位*//*
        val saveLimit = ControlBean(false ,"风琴帘-保存限位 ID:9")
        saveLimit.command = MGSerialPort.instance.getLeManLi().curtainAccordion().saveLimit(0)
        list.add(saveLimit)*/


        mIView.initControlList(list)
    }

}